package projectServlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.DAOException;
import dao.EmployeeDAO;
import dao.EmployeeDAOFactory;
import dto.UserDTO;

/**
 * Servlet implementation class InsertAdminServlet
 */
@WebServlet("/InsertAdminServlet")
public class InsertAdminServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InsertAdminServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		EmployeeDAO employeeload=EmployeeDAOFactory.loadInstance().getEmployeeDAO();
		String id=request.getParameter("Id");
		try {
		UserDTO employee=employeeload.findUser(Integer.parseInt(id));
		if(employee != null)
			employee.set_userID(Integer.parseInt(id));
			employee.set_name(request.getParameter("Name"));
		employee.set_gender(request.getParameter("Gender"));
		employee.set_domain(request.getParameter("Domain"));
		employee.set_domain(request.getParameter("TYPE"));
		employee.set_annualLeaveEntitlement(0);
		employee.set_annualLeave(0);
		employee.set_medicalLeaveEntitlement(0);
		employee.set_medicalLeave(0);
		employee.set_compensationLeave(0);
		employee.set_overTimeDays(0);
			employeeload.insertUser(employee);
		     //request.setAttribute("Users", employee);
		RequestDispatcher rd=request.getRequestDispatcher("adminnewPage.jsp");
		rd.forward(request, response);
		
		} catch (DAOException e) {
			e.printStackTrace();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		catch (ServletException e) {
			e.printStackTrace();
		}
	}
		
	}
